<template>
	<view class="My">
		<cu-custom bgColor="HomePageStyle">
			<block slot="content">姚记潮品订货</block>
		</cu-custom>
		<view class="NameAndAvatarArea">
			<view class="Avatar" @click="toLogin">
				<img :src="avatar" alt="" class="avatar" />
			</view>
			<view class="Name">
				<view class="NoLogin" v-if="!LoginOrNot">
					<view class="MainTitle">您尚未登录</view>
					<view class="SubTitle"> 点击下方登录/注册 </view>
				</view>
				<view class="Login" v-else>
					<view class="Phone">{{ MyInfoDetalis.phone }}</view>
					<view class="name">{{ MyInfoDetalis.nickName }}</view>
				</view>
			</view>
		</view>

		<view class="MyContent">
			<view class="MyFunctionItem" @click="ToAddress" v-if="LoginOrNot">
				<view class="ContactMerchantsLeft"> 收货地址 </view>
				<img :src="imgUrl + gameDetailsData.My.jt" class="jt" alt="" />
			</view>
			<view class="MyFunctionItem ContactMerchants">
				<view class="ContactMerchantsLeft"> 联系商家 </view>
				<img :src="imgUrl + gameDetailsData.My.jt" class="jt" alt="" />
			</view>
			<view class="MyFunctionItem MerchantAnnouncement">
				<view class="MerchantAnnouncementLeft"> 商家公告 </view>
				<view class="MerchantAnnouncementRight">
					<img :src="imgUrl + gameDetailsData.My.jt" class="jt" alt="" />
				</view>
			</view>
			<view class="MyFunctionItem Version">
				<view class="VersionLeft"> 关于姚记潮品 订货商城 </view>
				<view class="VersionRight">
					<view class="version"> 2.12.320 </view>
					<img :src="imgUrl + gameDetailsData.My.jt" alt="" class="jt" />
				</view>
			</view>
		</view>

		<view class="PhoneLogin" v-if="!LoginOrNot"> 手机号登录/注册 </view>
	</view>
</template>

<script>
	import gameDetails from "@/static/lib/public.js";
	export default {
		data() {
			return {
				token: "",

				LoginOrNot: "",

				gameDetailsData: gameDetails,

				imgUrl: this.$http.imgUrl,

				MyInfoDetalis: {},

				avatar: "",
			};
		},
		created() {
			this.LoginOrNot = this.IsLogin();
			if (this.LoginOrNot) {
				this.getUserInfo();
			}
		},
		methods: {
			toLogin() {
				if (!this.LoginOrNot) {
					uni.navigateTo({
						url: "/pages/login/login",
					});
				} else {
					uni.navigateTo({
						url: "/pagesA/My/EditUserInfo",
					});
				}
			},
			ToAddress() {
				uni.navigateTo({
					url: "/pagesA/My/Address",
				});
			},
			async getUserInfo() {
				const url = this.api.my.getUserInfo;
				const res = await this.$http.get(url, {});
				console.log(res.data, "获取个人信息");
				this.MyInfoDetalis = res.data.data;
				this.avatar = res.data.data.avatarUrl;
				// this.avatar = res.data.data.avatar;
				uni.setStorageSync("MyInfoDetalis", res.data.data);
			},
		},
	};
</script>

<style lang="scss" scoped>
	.My {
		position: relative;
		height: 100vh;

		.NameAndAvatarArea {
			width: 100%;
			height: 200rpx;
			display: flex;
			background-color: #4d86f6;

			.Avatar {
				width: 100rpx;
				height: 100rpx;
				background-color: #FFFFFF;
				border-radius: 50%;
				margin-left: 30rpx;

				.avatar {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}
			}

			.Name {
				display: flex;

				.NoLogin {
					margin-left: 20rpx;
					margin-top: 10rpx;
					color: #FFFFFF;

					.MainTitle {
						font-size: 32rpx;
						margin-bottom: 10rpx;
					}

					.SubTitle {
						font-size: 25rpx;
						font-weight: 400;
					}
				}

				.Login {
					margin-left: 20rpx;

					.Phone {
						color: #FFFFFF;
						font-size: 32rpx;
					}

					.name {
						margin-top: 40rpx;
						color: #FFFFFF;
					}
				}
			}
		}

		.jt {
			width: 10rpx;
			height: 20rpx;
		}

		.PhoneLogin {
			position: absolute;
			width: 716rpx;
			height: 86rpx;
			background: #f0f0f0;
			border-radius: 44rpx 44rpx 44rpx 44rpx;
			opacity: 1;
			top: 40%;
			margin-left: 20rpx;
			text-align: center;
			line-height: 86rpx;
			font-size: 28rpx;
			color: #666;
			opacity: 0.8;
		}

		.MyContent {
			position: absolute;
			width: 95%;
			top: 20%;
			left: 2.5%;
			background: #FFFFFF;
			border-radius: 35rpx;
			padding-left: 30rpx;

			.MyFunctionItem {
				height: 100rpx;
				line-height: 100rpx;
				border-bottom: 3rpx solid #ccc;

				&:last-child {
					border-bottom: 0rpx;
				}

				.jt {
					width: 24rpx;
					height: 24rpx;
				}
			}

			.ContactMerchants {
				width: 100%;
				display: flex;
				align-items: center;
				padding-right: 20rpx;
				justify-content: space-between;
			}

			.MerchantAnnouncement {
				display: flex;
				padding-right: 20rpx;
				justify-content: space-between;
				align-items: center;
			}

			.Version {
				display: flex;
				justify-content: space-between;

				.VersionRight {
					padding-right: 20rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.version {
						margin-right: 20rpx;
					}
				}
			}
		}
	}
</style>